﻿using System.Threading.Tasks;

using Furion.FriendlyException;

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

using Purchasing.Application;
using Purchasing.Application.ErrorCodes;
using Purchasing.Application.Services;

namespace Furion.Web.Entry.Controllers
{
    [AllowAnonymous]
    public class HomeController : Controller
    {
        private readonly ISystemService _systemService;
        private readonly ICompany _company;
        private readonly IMaterialLibraryService _libraryService;

        public HomeController(ISystemService systemService, ICompany company, IMaterialLibraryService libraryService)
        {
            _systemService = systemService;
            this._company = company;
            this._libraryService = libraryService;
        }

        public async Task<IActionResult> IndexAsync()
        {
            int topCount = 12;
            ViewBag.TopMaterialLibrary= await _libraryService.GetTopListAsync(topCount);

            return View();
        }

        public IActionResult Default()
        {
            ViewBag.Description = _systemService.GetDescription();

            return View();
        }

        public async  Task<IActionResult> GetCompanyAsync()
        {
            string str= await _company.GetAll("");
            return Content(str);
        }

        public IActionResult TestError()
        {
            //返回错误
            throw Oops.Oh(UserErrorCodes.u1000);
        }
    }
}